home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / HyperCard CTB Toolkit 1.0b2 / Source Code / CTBClose.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  1.9 KB  |  76 lines  |  [TEXT/MPS ]

  1. (*
  2.     CTBClose [abort] -- Close the current connection. If abort is present and non-empty then abort the
  3.         connection.
  4.  
  5.     To compile and link this file using Macintosh Programmer's Workshop,
  6.  
  7.         pascal -w CTBClose.p
  8.         link -m ENTRYPOINT -o HyperCommands -rt XCMD=2753 -sn Main=CTBClose ∂
  9.             CTBClose.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
  10.  
  11.     © Copyright 1990 by Apple Computer, Inc.
  12.  
  13.     Initial coding 2/90 by Harry R. Chesley.
  14. *)
  15.  
  16. {$R-}
  17.  
  18. {$S CTBClose }     { Segment name must be the same as the command name. }
  19.  
  20. unit DummyUnit;
  21.  
  22. interface
  23.  
  24. uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, HyperXCmd;
  25.  
  26. procedure EntryPoint(paramPtr: XCmdPtr);
  27.     
  28. implementation
  29.  
  30. procedure CTBClose(paramPtr: XCmdPtr); forward;
  31.  
  32. procedure EntryPoint(paramPtr: XCmdPtr);
  33.  
  34.     begin
  35.         CTBClose(paramPtr);
  36.     end;
  37.  
  38. procedure CTBClose(paramPtr: XCmdPtr);
  39.  
  40.     {$I CTBUtil.inc}
  41.  
  42.     var sizes: CMBufferSizes;
  43.         status: CMStatFlags;
  44.         ignore: OSErr;
  45.  
  46.     procedure Fail(errMsg: Str255); { set theResult and quit }
  47.         begin
  48.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  49.             exit(CTBClose);
  50.         end;
  51.  
  52.     begin
  53.         { Check the parameter count. }
  54.         if paramPtr^.paramCount > 1 then Fail('Invalid parameter count');
  55.  
  56.         { Make sure the Comm Toolbox is here. }
  57.         CTBReady;
  58.  
  59.         { Only close if there's something to close. }
  60.         if Globals^^.connHand <> nil then
  61.             if CMStatus(Globals^^.connHand,sizes,status) = noErr then
  62.                 begin
  63.                     { Only close if we're open or opening; if we're listening, then accept. }
  64.                     if Band(status,cmStatusOpen+cmStatusOpening) <> 0 then
  65.                         begin
  66.                             if ParmPresent(1) or (Band(status,cmStatusOpening) <> 0) then
  67.                                 ignore := CMAbort(Globals^^.connHand);
  68.                             FailOSErr(CMClose(Globals^^.connHand,false,nil,3600,ParmPresent(1)));
  69.                         end
  70.                     else if Band(status,cmStatusListenPend+cmStatusIncomingCallPresent) <> 0 then
  71.                         FailOSErr(CMAccept(Globals^^.connHand,false));
  72.                 end;
  73.     end;
  74.  
  75. end.
  76.